package fr.cephb.joperon.core.entities;

import fr.cephb.joperon.core.bio.AcidNucleicUtil;



public class DnaSeq
{
public static final int SIZEOF=4;
private byte array[];
private int byteIndex;
public DnaSeq(byte array[],int byteIndex)
	{
	if(byteIndex+SIZEOF>array.length) throw new IndexOutOfBoundsException("byteIndex="+byteIndex+" and sequence.length="+array.length);
	this.array=array;
	this.byteIndex=byteIndex;
	}

private boolean bitAt(int index)
	{
	return (this.array[ this.byteIndex + index/8]&(1<<(index%8))) > 0;
	}

public void debug()
	{
	for(int i=0;i< SIZEOF*8;++i)
		{
		System.err.print(bitAt(i)?1:0);
		if(i+1==6 || i+1==10) System.err.print(" ");
		}
	System.err.print(" ");
	
	int i=0;
	if(bitAt(6)) i+=8;
	if(bitAt(7)) i+=4;
	if(bitAt(8)) i+=2;
	if(bitAt(9)) i+=1;
	System.err.print(" "+i);
	
	
	System.err.print(" "+i+ AcidNucleicUtil.decode(i, false));
	
	
	System.err.println();
	}

public char getRefBase()
	{

	return (char)((array[byteIndex] & 0xff) << 6);
	}

public char getBase()
	{
	int i=0;
	if(bitAt(6)) i+=1;
	if(bitAt(7)) i+=2;
	if(bitAt(8)) i+=4;
	if(bitAt(9)) i+=8;
	return AcidNucleicUtil.decode(i);
	}

/*
unsigned int  alt: 6;           1. alt: alternative base  base alternative degenerate code (if any) whitespace si rien
unsigned int  ref: 4;            2. ref: reference base  la base de reference
unsigned int  ins: 1;           3. ins: insertion true/false
unsigned int  par: 1;            4. par: paralog tout a zero (will be used )
unsigned int  rep: 1;            5. rep: repeat region  true/false
unsigned int  cpg: 1;            6. cpg: CpG islands  true/false
unsigned int  one: 1;             7. one: mem 1 (will be used )
unsigned int  two: 1;             8. two: mem 2 (will be used)

*/
}
